/****************************************************************************
 * Copyright (C) 2025 Chenyz. All rights reserved.
 *
 * @file    my_muti_button.h
 *
 * @par     dependencies
 *          - stdio.h
 *          - stdint.h
 *          - stdbool.h
 *          - string.h
 *
 * @author  Chenyz
 *
 * @brief   LED driver hardware abstraction layer with following features:
 *          - Configurable blinking patterns and duty cycles
 *          - Cross-platform time management (bare-metal/RTOS)
 *          - Hardware-agnostic operation interface
 *
 * @version V1.0
 * @date    2025-05-11
 *
 * @note    Coding standard:
 *          - 1 tab == 4 spaces
 *          - Follow ISO C99 standard
 *
 ***************************************************************************/

#ifndef __MY_MULTI_BUTTON_H__
#define __MY_MULTI_BUTTON_H__

/******************************** Includes *********************************/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/******************************** Defines **********************************/
#define NUMBER_OF_EVENTS (15U)
/*  Button Event    */
#define BUTTON_PRESS_DOWN       (1U)
#define BUTTON_PRESS_UP         (2U)
#define BUTTON_DOUBLE_CLICK     (3U)
#define BUTTON_TRIPLE_CLICK     (4U)
#define BUTTON_LONG_PRESS_START (5U)
#define BUTTON_LONG_PRESS_HOLD  (6U)
#define BUTTON_NO_PRESS         (0xFF)
/*  Button Status    */
#define BUTTON_IDLE_STATUS                (0U)
#define BUTTON_PRESS_STATUS               (1U)
#define BUTTON_RELEASE_STATUS             (2U)
#define BUTTON_DOUBLE_CLICK_STATUS        (3U)
#define BUTTON_DOUBLE_CLICKRELEASE_STATUS (4U)
#define BUTTON_TRIPLE_CLICK_STATUS        (5U)
#define BUTTON_HOLDING_STATUS             (6U)

/*  Button Level    */
#define BUTTON_LOW_LEVEL  (0U)
#define BUTTON_HIGH_LEVEL (1U)

#define TICKS_INTERVAL_MS (5U)
#define DEBOUNCE_TICKS    (3U)
#define SHORT_PRESS_TICKS (500U / TICKS_INTERVAL_MS)
#define LONG_PRESS_TICKS  (3000U / TICKS_INTERVAL_MS)
/***************************** Type Definitions ****************************/
typedef void (*ButtonCallBacks)(void);
typedef struct ButtonType
{
    uint8_t            ButtonStatus;
    uint16_t           ButtonTicks;
    uint8_t            ButtonDebounceCount;
    uint8_t            ButtonEvent;
    uint8_t            ButtonRepeat;
    uint8_t            (*pfButtonGetLevel)(uint8_t ButtonID);
    uint8_t            ButtonActiveLevel;
    uint8_t            ButtonCurrentLevel;
    uint8_t            ButtonID;
    struct ButtonType *ButtonNext;
    ButtonCallBacks    ButtonCallBacksArray[NUMBER_OF_EVENTS];
    /* data */
} ButtonType;
/*************************** Function Declarations **************************/

void    Button_Init(ButtonType *ButtonInstance,
                    uint8_t     (*pfButtonGetLevel)(uint8_t ButtonID),
                    uint8_t     ButtonActiveLevel,
                    uint8_t     ButtonID);
void    Button_Process(ButtonType *ButtonInstance);
bool    Button_Register(ButtonType *ButtonInstance);
bool    Button_UnRegister(uint8_t ButtonID);
uint8_t Button_Get_Event(ButtonType *ButtonInstance);
void    Button_Callbacks_Attach(ButtonType     *ButtonInstance,
                                uint8_t         ButtonEvent,
                                ButtonCallBacks Callback);
void    Button_List_Porcess(void);
#endif
